package me.shurufa.controller;

import java.util.List;

import me.shurufa.bean.Book;
import me.shurufa.bean.BookComment;
import me.shurufa.bean.Excerpt;
import me.shurufa.utils.Utils;

/**
 * Create by andy (https://github.com/andyxialm)
 * Create time: 16/5/12 14:18
 * Description :
 */
public class DataController {
    /**
     * 书籍列表去重复
     * @param localList
     * @param newDataList
     * @return
     */
    public static List<Book> getValidDataList(List<Book> localList, List<Book> newDataList) {
        if (Utils.isNullForList(localList)) {
            return newDataList;
        }

        if (Utils.isNullForList(newDataList)) {
            return null;
        }

        try {
            for (Book localBook : localList) {
                for (Book newDataBook : newDataList) {
                    if (localBook.id == newDataBook.id) {
                        newDataList.remove(newDataBook);
                        break;
                    }
                }
            }
        } catch (Exception e) {
        } finally {
            return newDataList;
        }
    }

    /**
     * 书摘列表去重复
     * @param localList
     * @param newDataList
     * @return
     */
    public static List<Excerpt> getValidExcerptList(List<Excerpt> localList, List<Excerpt> newDataList) {
        if (Utils.isNullForList(localList)) {
            return newDataList;
        }

        if (Utils.isNullForList(newDataList)) {
            return null;
        }

        try {
            for (Excerpt localBook : localList) {
                for (Excerpt newDataBook : newDataList) {
                    if (localBook.id == newDataBook.id) {
                        newDataList.remove(newDataBook);
                        break;
                    }
                }
            }
        } catch (Exception e) {
        } finally {
            return newDataList;
        }
    }

    /**
     * 书评列表去重复
     * @param localList   本地列表
     * @param newDataList 新数据列表
     * @return
     */
    public static List<BookComment> getValidBookCommentList(List<BookComment> localList, List<BookComment> newDataList) {
        if (Utils.isNullForList(localList)) {
            return newDataList;
        }

        if (Utils.isNullForList(newDataList)) {
            return null;
        }

        try {
            for (BookComment localBook : localList) {
                for (BookComment newDataBook : newDataList) {
                    if (localBook.id == newDataBook.id) {
                        newDataList.remove(newDataBook);
                        break;
                    }
                }
            }
        } catch (Exception e) {
        } finally {
            return newDataList;
        }
    }
}
